import { _decorator, AudioClip, Component, director, profiler, sys } from 'cc';
import { Cons } from './tools/Cons';
import { SceneManager } from './tools/SceneManager';
import { UserInfoCollector } from './tools/UserInfoCollector';
import { L, LogLevel } from './tools/L';
import { AudioManager } from './tools/AudioManager';
const { ccclass, property } = _decorator;

@ccclass('StartScene')
export class StartScene extends Component {
    @property(AudioClip)
    buttonAudioClip: AudioClip | null = null;    

    async onLoad() {
        profiler.hideStats();
        if(sys.platform === sys.Platform.WECHAT_GAME) {
            L.level = LogLevel.WARN;
        }
        // 1. 初始化用户信息收集
        await UserInfoCollector.init();
        // 2. 配置Logger
        L.configure({
            // uploadUrl: 'https://api.yourgame.com/logs',
            userInfo: {
                ... UserInfoCollector.userInfo,
                appVersion: 'fixme-appVersion-get'
            }
        });

        // 3. 测试日志
        L.info('SYSTEM', 'Log system initialized', {
            platform: UserInfoCollector.userInfo.platform
        });

        // 4. 错误捕获
        window.onerror = (msg, url, line) => {
            L.error('GLOBAL', `Uncaught error: ${msg}`, { url, line });
        };
    }

    startGame() {
        AudioManager.inst.playOneShot(this.buttonAudioClip);
        SceneManager.inst.loadScene(Cons.SCENES.GAME);
    }
}

